package org.eweb4j.mvc.config.creator;

import java.lang.annotation.Annotation;

import org.eweb4j.mvc.validator.annotation.ChineseVal;
import org.eweb4j.mvc.validator.annotation.DateVal;
import org.eweb4j.mvc.validator.annotation.EmailVal;
import org.eweb4j.mvc.validator.annotation.EnumVal;
import org.eweb4j.mvc.validator.annotation.EqualsVal;
import org.eweb4j.mvc.validator.annotation.ForbidVal;
import org.eweb4j.mvc.validator.annotation.IDCardVal;
import org.eweb4j.mvc.validator.annotation.IPVal;
import org.eweb4j.mvc.validator.annotation.IntVal;
import org.eweb4j.mvc.validator.annotation.LengthVal;
import org.eweb4j.mvc.validator.annotation.MyValidator;
import org.eweb4j.mvc.validator.annotation.PhoneVal;
import org.eweb4j.mvc.validator.annotation.QQVal;
import org.eweb4j.mvc.validator.annotation.RegexVal;
import org.eweb4j.mvc.validator.annotation.RequiredVal;
import org.eweb4j.mvc.validator.annotation.SizeVal;
import org.eweb4j.mvc.validator.annotation.UrlVal;
import org.eweb4j.mvc.validator.annotation.ZipVal;


/**
 * 应用工厂模式,创建不同的验证器处理
 * 
 * @author weiwei
 * 
 */
public class ValidatorFactory {
	public static ValidatorCreator get(Annotation ann) {
		Class<?> cls = ann.annotationType();
		String clsName = cls.getName();
		if (ChineseVal.class.getName().equals(clsName))
			return new ChineseImpl((ChineseVal) ann);
		else if (DateVal.class.getName().equals(clsName))
			return new DateImpl((DateVal) ann);
		else if (EmailVal.class.getName().equals(clsName))
			return new EmailImpl((EmailVal) ann);
		else if (EnumVal.class.getName().equals(clsName))
			return new EnumImpl((EnumVal) ann);
		else if (EqualsVal.class.getName().equals(clsName))
			return new EqualsImpl((EqualsVal) ann);
		else if (ForbidVal.class.getName().equals(clsName))
			return new ForbidImpl((ForbidVal) ann);
		else if (IDCardVal.class.getName().equals(clsName))
			return new IDCardImpl((IDCardVal) ann);
		else if (IntVal.class.getName().equals(clsName))
			return new IntImpl((IntVal) ann);
		else if (IPVal.class.getName().equals(clsName))
			return new IpImpl((IPVal) ann);
		else if (LengthVal.class.getName().equals(clsName))
			return new LengthImpl((LengthVal) ann);
		else if (PhoneVal.class.getName().equals(clsName))
			return new PhoneImpl((PhoneVal) ann);
		else if (QQVal.class.getName().equals(clsName))
			return new QQImpl((QQVal) ann);
		else if (RegexVal.class.getName().equals(clsName))
			return new RegexImpl((RegexVal) ann);
		else if (RequiredVal.class.getName().equals(clsName))
			return new RequiredImpl((RequiredVal) ann);
		else if (SizeVal.class.getName().equals(clsName))
			return new SizeImpl((SizeVal) ann);
		else if (UrlVal.class.getName().equals(clsName))
			return new UrlImpl((UrlVal) ann);
		else if (ZipVal.class.getName().equals(clsName))
			return new ZipImpl((ZipVal) ann);
		else if (MyValidator.class.getName().equals(clsName))
			return new MyValidatorImpl((MyValidator) ann);

		return null;
	}
}
